/*
    This file is part of Posixcpp library.

    Posixcpp library is free software: you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public License
    as published by the Free Software Foundation, either version 3 of
    the License, or (at your option) any later version.

    Posixcpp library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU LesserGeneral Public
    License along with Posixcpp library. If not, see
    <http://www.gnu.org/licenses/>.
 */

#ifndef POSIX_THREADS_HPP_INCLUDED
#define POSIX_THREADS_HPP_INCLUDED

#include <pthread.h>

#include "posixcpp.hpp"

namespace posix
{
/**
 * @namespace threads
 * @brief Namespace of threading functions
 */
namespace threads
{
/**
 * @enum SchedulerPolicy_t
 * @brief Thread scheduling policy enumeration
 */
enum class SchedulerPolicy_t
{
    /**
     * Default OS specific policy
     */
    DEFAULT = SCHED_OTHER,
    /**
     * Quant based real-time policy
     */
    ROUND_ROBIN = SCHED_RR,
    /**
     * First in first out real-time policy
     */
    FIFO = SCHED_FIFO
};
/**
 * @struct SchedulerParameters_t
 * @brief parameters of the threads scheduler
 */
struct SchedulerParameters_t
{
    SchedulerPolicy_t policy;
    int priority;
};
/**
 * @enum CancelState_t
 * @brief Cancel state of the thread
 */
enum class CancelState_t
{
    /**
     * Cancelation enabled
     */
    ENABLE = PTHREAD_CANCEL_ENABLE,
    /**
     * Cancelation disabled
     */
    DISABLE = PTHREAD_CANCEL_DISABLE
};

/**
 * @enum CancelType_t
 * @brief Cancelation request processing type
 */
enum class CancelType_t
{
    /**
     * The cancelation request should be deferred until the cancelation-point function
     * will be executed
     */
    DEFERRED = PTHREAD_CANCEL_DEFERRED,
    /**
     * Dangerous asynchronous cancelation
     */
    ASYNCHRONOUS = PTHREAD_CANCEL_ASYNCHRONOUS
};
/**
 * @enum SchedulerInheritance_t
 * @brief Scheduler inheritance mode for the spawning threads
 */
enum class SchedulerInheritance_t
{
    INHERIT = PTHREAD_INHERIT_SCHED,
    EXPLICIT = PTHREAD_EXPLICIT_SCHED
};

std::ostream & operator<<(std::ostream & stream, SchedulerPolicy_t policy);
std::ostream & operator<<(std::ostream & stream, SchedulerParameters_t params);
std::ostream & operator<<(std::ostream & stream, CancelState_t state);
std::ostream & operator<<(std::ostream & stream, CancelType_t type);
std::ostream & operator<<(std::ostream & stream, SchedulerInheritance_t mode);

}
}

#endif // POSIX_THREADS_HPP_INCLUDED
